{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "using Mamba"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "using Stan"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "const bernoullistanmodel = \"\n",
    "data { \n",
    "  int<lower=0> N; \n",
    "  int<lower=0,upper=1> y[N];\n",
    "} \n",
    "parameters {\n",
    "  real<lower=0,upper=1> theta;\n",
    "} \n",
    "model {\n",
    "  theta ~ beta(1,1);\n",
    "    y ~ bernoulli(theta);\n",
    "}\n",
    "\";"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "  name =                    \"bernoulli\"\n",
      "  nchains =                 4\n",
      "  num_samples =             1000\n",
      "  num_warmup =                   1000\n",
      "  thin =                    1\n",
      "  useMamba =                true\n",
      "  mambaThinning =           1\n",
      "  monitors =                String[]\n",
      "  model_file =              \"bernoulli.stan\"\n",
      "  data_file =               \"\"\n",
      "  output =                  Output()\n",
      "    file =                    \"\"\n",
      "    diagnostics_file =        \"\"\n",
      "    refresh =                 100\n",
      "  method =                  Sample()\n",
      "    num_samples =             1000\n",
      "    num_warmup =              1000\n",
      "    save_warmup =             false\n",
      "    thin =                    1\n",
      "    algorithm =               HMC()\n",
      "      engine =                  NUTS()\n",
      "        max_depth =               10\n",
      "      metric =                  "
     ]
    },
    {
     "data": {
      "text/plain": []
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Stan.diag_e\n",
      "      stepsize =                1.0\n",
      "      stepsize_jitter =         1.0\n",
      "    adapt =                   Adapt()\n",
      "      gamma =                   0.05\n",
      "      delta =                   0.8\n",
      "      kappa =                   0.75\n",
      "      t0 =                      10.0\n",
      "      init_buffer =             75\n",
      "      term_buffer =             50\n",
      "      window =                  25\n"
     ]
    }
   ],
   "source": [
    "stanmodel = Stanmodel(name=\"bernoulli\", model=bernoullistanmodel)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Dict{String,Any} with 2 entries:\n",
       "  \"N\" => 10\n",
       "  \"y\" => [0, 1, 0, 1, 0, 0, 0, 0, 0, 1]"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "bernoullidata = Dict(\"N\" => 10, \"y\" => [0, 1, 0, 1, 0, 0, 0, 0, 0, 1])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Sometimes output of CmdStan is not displayed properly. Usually re-running this cell by itself fixes this.\n",
    "\n",
    "### Also note that if the stan script has already been compiled and built, make will not repeat these steps."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "make: `/Users/rob/Downloads/tmp/bernoulli' is up to date.\n",
      "\n",
      "Length of data array is not equal to nchains,\n",
      "all chains will use the first data dictionary.\n",
      "\n",
      "Calling /Users/rob/Projects/StanSupport/cmdstan/bin/stansummary to infer across chains.\n",
      "\n",
      "Inference for Stan model: bernoulli_model\n",
      "4 chains: each with iter=(1000,1000,1000,1000); warmup=(0,0,0,0); thin=(1,1,1,1); 4000 iterations saved.\n",
      "\n",
      "Warmup took (0.0092, 0.016, 0.016, 0.016) seconds, 0.057 seconds total\n",
      "Sampling took (0.022, 0.040, 0.043, 0.040) seconds, 0.14 seconds total\n",
      "\n",
      "                Mean     MCSE  StdDev    5%   50%   95%  N_Eff  N_Eff/s    R_hat\n",
      "lp__            -8.1  1.6e-02    0.67  -9.4  -7.9  -7.6   1857    12828  1.0e+00\n",
      "accept_stat__   0.92  1.9e-03    0.12  0.65  0.97   1.0   4000    27630  1.0e+00\n",
      "stepsize__       1.0  8.9e-02    0.13  0.95  1.00   1.3    2.0       14  5.6e+13\n",
      "treedepth__      1.4  7.8e-03    0.49   1.0   1.0   2.0   3883    26820  1.0e+00\n",
      "n_leapfrog__     2.5  5.0e-02     1.3   1.0   3.0   3.0    650     4493  1.0e+00\n",
      "divergent__     0.00  0.0e+00    0.00  0.00  0.00  0.00   4000    27630      nan\n",
      "energy__         8.6  2.5e-02    0.98   7.7   8.4    11   1547    10687  1.0e+00\n",
      "theta           0.33  3.1e-03    0.13  0.14  0.32  0.55   1689    11669  1.0e+00\n",
      "\n",
      "Samples were drawn using hmc with nuts.\n",
      "For each parameter, N_Eff is a crude measure of effective sample size,\n",
      "and R_hat is the potential scale reduction factor on split chains (at \n",
      "convergence, R_hat=1).\n",
      "\n"
     ]
    }
   ],
   "source": [
    "rc, sim1 = stan(stanmodel, [bernoullidata], pwd(), CmdStanDir=CMDSTAN_HOME);"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### What's the structure of a Mamba.Chains object"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Mamba.Chains"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "typeof(sim1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(1000, 8, 4)"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "size(sim1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4-element Array{Symbol,1}:\n",
       " :value \n",
       " :range \n",
       " :names \n",
       " :chains"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "fieldnames(sim1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "8-element Array{AbstractString,1}:\n",
       " \"lp__\"         \n",
       " \"accept_stat__\"\n",
       " \"stepsize__\"   \n",
       " \"treedepth__\"  \n",
       " \"n_leapfrog__\" \n",
       " \"divergent__\"  \n",
       " \"energy__\"     \n",
       " \"theta\"        "
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sim1.names"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### If return code == 0, filter sim1 output and call Mamba's describe()."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Subset Sampler Output\n",
      "Iterations = 1:1000\n",
      "Thinning interval = 1\n",
      "Chains = 1,2,3,4\n",
      "Samples per chain = 1000\n",
      "\n",
      "Empirical Posterior Estimates:\n",
      "                  Mean        SD       Naive SE       MCSE      ESS\n",
      "         lp__ -8.12864507 0.67144367 0.0106164566 0.0154961591 1000\n",
      "        theta  0.32867301 0.12640946 0.0019987091 0.0031223402 1000\n",
      "accept_stat__  0.91868808 0.12243779 0.0019359115 0.0029870001 1000\n",
      "\n",
      "Quantiles:\n",
      "                 2.5%       25.0%       50.0%      75.0%       97.5%  \n",
      "         lp__ -9.9433640 -8.29392750 -7.8834950 -7.69665500 -7.6387900\n",
      "        theta  0.1188135  0.23013675  0.3193140  0.41652875  0.5894945\n",
      "accept_stat__  0.5466045  0.89072425  0.9702025  1.00000000  1.0000000\n",
      "\n"
     ]
    }
   ],
   "source": [
    "if rc == 0\n",
    "  println(\"Subset Sampler Output\")\n",
    "  sim = sim1[1:1000, [\"lp__\", \"theta\", \"accept_stat__\"], :]\n",
    "  describe(sim)\n",
    "end"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Brooks, Gelman and Rubin Convergence Diagnostic\n",
    "\n",
    "### Note that all below diagnostic routines should be bracketed by `if rc == 0 ... end`."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\u001b[1m\u001b[33mWARNING: \u001b[39m\u001b[22m\u001b[33mlog{T <: Number}(x::AbstractArray{T}) is deprecated, use log.(x) instead.\u001b[39m"
     ]
    },
    {
     "data": {
      "text/plain": [
       "               PSRF 97.5%\n",
       "         lp__ 1.003 1.006\n",
       "        theta 1.004 1.012\n",
       "accept_stat__ 1.052 1.088\n",
       " Multivariate 1.032   NaN\n",
       "\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\n",
      "Stacktrace:\n",
      " [1] \u001b[1mdepwarn\u001b[22m\u001b[22m\u001b[1m(\u001b[22m\u001b[22m::String, ::Symbol\u001b[1m)\u001b[22m\u001b[22m at \u001b[1m./deprecated.jl:70\u001b[22m\u001b[22m\n",
      " [2] \u001b[1mlog\u001b[22m\u001b[22m\u001b[1m(\u001b[22m\u001b[22m::Array{Float64,2}\u001b[1m)\u001b[22m\u001b[22m at \u001b[1m./deprecated.jl:57\u001b[22m\u001b[22m\n",
      " [3] \u001b[1mlink\u001b[22m\u001b[22m\u001b[1m(\u001b[22m\u001b[22m::Mamba.Chains\u001b[1m)\u001b[22m\u001b[22m at \u001b[1m/Users/rob/.julia/v0.6/Mamba/src/output/chains.jl:242\u001b[22m\u001b[22m\n",
      " [4] \u001b[1m#gelmandiag#104\u001b[22m\u001b[22m\u001b[1m(\u001b[22m\u001b[22m::Float64, ::Bool, ::Bool, ::Function, ::Mamba.Chains\u001b[1m)\u001b[22m\u001b[22m at \u001b[1m/Users/rob/.julia/v0.6/Mamba/src/output/gelmandiag.jl:9\u001b[22m\u001b[22m\n",
      " [5] \u001b[1m(::Mamba.#kw##gelmandiag)\u001b[22m\u001b[22m\u001b[1m(\u001b[22m\u001b[22m::Array{Any,1}, ::Mamba.#gelmandiag, ::Mamba.Chains\u001b[1m)\u001b[22m\u001b[22m at \u001b[1m./<missing>:0\u001b[22m\u001b[22m\n",
      " [6] \u001b[1minclude_string\u001b[22m\u001b[22m\u001b[1m(\u001b[22m\u001b[22m::String, ::String\u001b[1m)\u001b[22m\u001b[22m at \u001b[1m./loading.jl:515\u001b[22m\u001b[22m\n",
      " [7] \u001b[1minclude_string\u001b[22m\u001b[22m\u001b[1m(\u001b[22m\u001b[22m::Module, ::String, ::String\u001b[1m)\u001b[22m\u001b[22m at \u001b[1m/Users/rob/.julia/v0.6/Compat/src/Compat.jl:407\u001b[22m\u001b[22m\n",
      " [8] \u001b[1mexecute_request\u001b[22m\u001b[22m\u001b[1m(\u001b[22m\u001b[22m::ZMQ.Socket, ::IJulia.Msg\u001b[1m)\u001b[22m\u001b[22m at \u001b[1m/Users/rob/.julia/v0.6/IJulia/src/execute_request.jl:154\u001b[22m\u001b[22m\n",
      " [9] \u001b[1meventloop\u001b[22m\u001b[22m\u001b[1m(\u001b[22m\u001b[22m::ZMQ.Socket\u001b[1m)\u001b[22m\u001b[22m at \u001b[1m/Users/rob/.julia/v0.6/IJulia/src/eventloop.jl:8\u001b[22m\u001b[22m\n",
      " [10] \u001b[1m(::IJulia.##14#17)\u001b[22m\u001b[22m\u001b[1m(\u001b[22m\u001b[22m\u001b[1m)\u001b[22m\u001b[22m at \u001b[1m./task.jl:335\u001b[22m\u001b[22m\n",
      "while loading In[14], in expression starting on line 2\n"
     ]
    }
   ],
   "source": [
    "try\n",
    "  gelmandiag(sim, mpsrf=true, transform=true) |> display\n",
    "catch e\n",
    "  #println(e)\n",
    "  gelmandiag(sim, mpsrf=false, transform=true) |> display\n",
    "end"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Geweke Convergence Diagnostic"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "              Z-score p-value\n",
       "         lp__   0.657  0.5113\n",
       "        theta   0.994  0.3203\n",
       "accept_stat__   2.438  0.0148\n",
       "\n",
       "              Z-score p-value\n",
       "         lp__  -1.825  0.0679\n",
       "        theta   0.000  0.9998\n",
       "accept_stat__   0.018  0.9854\n",
       "\n",
       "              Z-score p-value\n",
       "         lp__  -0.281  0.7783\n",
       "        theta  -0.034  0.9731\n",
       "accept_stat__  -0.982  0.3260\n",
       "\n",
       "              Z-score p-value\n",
       "         lp__  -0.988  0.3232\n",
       "        theta  -1.877  0.0606\n",
       "accept_stat__  -0.725  0.4682\n",
       "\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "gewekediag(sim) |> display"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Highest Posterior Density Intervals"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "              95% Lower 95% Upper\n",
       "         lp__ -9.429950 -7.638170\n",
       "        theta  0.115025  0.581819\n",
       "accept_stat__  0.654388  1.000000\n",
       "\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "hpd(sim) |> display"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Cross-Correlations"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "                 lp__       theta    accept_stat__\n",
       "         lp__ 1.00000000  0.04377643    0.41730895\n",
       "        theta 0.04377643  1.00000000   -0.07680032\n",
       "accept_stat__ 0.41730895 -0.07680032    1.00000000\n",
       "\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "cor(sim) |> display"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Lag-Autocorrelations"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "                  Lag 1        Lag 5         Lag 10         Lag 50   \n",
       "         lp__   0.32016258  -0.017256870    0.027960976  0.0324091917\n",
       "        theta   0.38801658   0.012344096   -0.034038246  0.0097314316\n",
       "accept_stat__  -0.09665741   0.026337036    0.041742658 -0.0422834258\n",
       "\n",
       "                  Lag 1        Lag 5         Lag 10         Lag 50   \n",
       "         lp__  0.276833585 -0.0011036154    0.071220839  0.0066471642\n",
       "        theta  0.402378185  0.0397211474    0.008000695 -0.0314988447\n",
       "accept_stat__ -0.046943386 -0.0533491235    0.050268445 -0.0040709876\n",
       "\n",
       "                  Lag 1        Lag 5         Lag 10         Lag 50   \n",
       "         lp__   0.42141370  0.0199876342    0.065692544 -0.0046114129\n",
       "        theta   0.42027822 -0.0060865494    0.014326021 -0.0042476505\n",
       "accept_stat__  -0.07515192 -0.0131331858    0.057966881  0.0656034097\n",
       "\n",
       "                  Lag 1        Lag 5         Lag 10         Lag 50   \n",
       "         lp__  0.351582623    0.02746748  0.00041632276   0.036462336\n",
       "        theta  0.371604221   -0.03279530  0.03238283149  -0.046004024\n",
       "accept_stat__ -0.043927806   -0.01691960 -0.01122697291   0.027470922\n",
       "\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "autocor(sim) |> display"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Create plot files"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "WARNING: Compat.UTF8String is deprecated, use String instead.\n",
      "  likely near In[19]:2\n",
      "WARNING: Compat.UTF8String is deprecated, use String instead.\n",
      "  likely near In[19]:2\n",
      "WARNING: Compat.UTF8String is deprecated, use String instead.\n",
      "  likely near In[19]:2\n",
      "WARNING: Compat.ASCIIString is deprecated, use String instead.\n",
      "  likely near In[19]:2\n",
      "WARNING: Compat.ASCIIString is deprecated, use String instead.\n",
      "  likely near In[19]:2\n",
      "WARNING: Compat.ASCIIString is deprecated, use String instead.\n",
      "  likely near In[19]:2\n",
      "WARNING: Compat.ASCIIString is deprecated, use String instead.\n",
      "  likely near In[19]:2\n",
      "WARNING: Compat.ASCIIString is deprecated, use String instead.\n",
      "  likely near In[19]:2\n",
      "WARNING: Compat.ASCIIString is deprecated, use String instead.\n",
      "  likely near In[19]:2\n",
      "WARNING: Compat.ASCIIString is deprecated, use String instead.\n",
      "  likely near In[19]:2\n",
      "WARNING: Compat.ASCIIString is deprecated, use String instead.\n",
      "  likely near In[19]:2\n",
      "WARNING: Compat.ASCIIString is deprecated, use String instead.\n",
      "  likely near In[19]:2\n",
      "WARNING: Compat.ASCIIString is deprecated, use String instead.\n",
      "  likely near In[19]:2\n",
      "WARNING: Compat.ASCIIString is deprecated, use String instead.\n",
      "  likely near In[19]:2\n",
      "WARNING: Compat.ASCIIString is deprecated, use String instead.\n",
      "  likely near In[19]:2\n",
      "WARNING: Compat.ASCIIString is deprecated, use String instead.\n",
      "  likely near In[19]:2\n",
      "WARNING: Compat.ASCIIString is deprecated, use String instead.\n",
      "  likely near In[19]:2\n",
      "WARNING: Compat.ASCIIString is deprecated, use String instead.\n",
      "  likely near In[19]:2\n",
      "WARNING: Compat.ASCIIString is deprecated, use String instead.\n",
      "  likely near In[19]:2\n",
      "WARNING: Compat.ASCIIString is deprecated, use String instead.\n",
      "  likely near In[19]:2\n",
      "WARNING: Compat.ASCIIString is deprecated, use String instead.\n",
      "  likely near In[19]:2\n",
      "WARNING: Compat.ASCIIString is deprecated, use String instead.\n",
      "  likely near In[19]:2\n",
      "WARNING: Compat.ASCIIString is deprecated, use String instead.\n",
      "  likely near In[19]:2\n",
      "WARNING: Compat.ASCIIString is deprecated, use String instead.\n",
      "  likely near In[19]:2\n",
      "WARNING: Compat.ASCIIString is deprecated, use String instead.\n",
      "  likely near In[19]:2\n",
      "WARNING: Compat.ASCIIString is deprecated, use String instead.\n",
      "  likely near In[19]:2\n",
      "WARNING: Compat.ASCIIString is deprecated, use String instead.\n",
      "  likely near In[19]:2\n",
      "WARNING: Compat.ASCIIString is deprecated, use String instead.\n",
      "  likely near In[19]:2\n",
      "WARNING: Compat.ASCIIString is deprecated, use String instead.\n",
      "  likely near In[19]:2\n",
      "WARNING: Compat.ASCIIString is deprecated, use String instead.\n",
      "  likely near In[19]:2\n",
      "WARNING: Compat.ASCIIString is deprecated, use String instead.\n",
      "  likely near In[19]:2\n",
      "WARNING: Compat.ASCIIString is deprecated, use String instead.\n",
      "  likely near In[19]:2\n",
      "WARNING: Compat.ASCIIString is deprecated, use String instead.\n",
      "  likely near In[19]:2\n",
      "WARNING: Compat.ASCIIString is deprecated, use String instead.\n",
      "  likely near In[19]:2\n",
      "WARNING: Compat.ASCIIString is deprecated, use String instead.\n",
      "  likely near In[19]:2\n",
      "WARNING: Compat.ASCIIString is deprecated, use String instead.\n",
      "  likely near In[19]:2\n",
      "WARNING: Compat.ASCIIString is deprecated, use String instead.\n",
      "  likely near In[19]:2\n",
      "WARNING: Compat.ASCIIString is deprecated, use String instead.\n",
      "  likely near In[19]:2\n",
      "WARNING: Compat.ASCIIString is deprecated, use String instead.\n",
      "  likely near In[19]:2\n",
      "WARNING: Compat.ASCIIString is deprecated, use String instead.\n",
      "  likely near In[19]:2\n",
      "WARNING: Compat.ASCIIString is deprecated, use String instead.\n",
      "  likely near In[19]:2\n",
      "WARNING: Compat.ASCIIString is deprecated, use String instead.\n",
      "  likely near In[19]:2\n",
      "WARNING: Compat.ASCIIString is deprecated, use String instead.\n",
      "  likely near In[19]:2\n",
      "WARNING: Compat.ASCIIString is deprecated, use String instead.\n",
      "  likely near In[19]:2\n",
      "WARNING: Compat.ASCIIString is deprecated, use String instead.\n",
      "  likely near In[19]:2\n",
      "WARNING: Compat.ASCIIString is deprecated, use String instead.\n",
      "  likely near In[19]:2\n",
      "WARNING: Compat.ASCIIString is deprecated, use String instead.\n",
      "  likely near In[19]:2\n",
      "WARNING: Compat.ASCIIString is deprecated, use String instead.\n",
      "  likely near In[19]:2\n",
      "WARNING: Compat.UTF8String is deprecated, use String instead.\n",
      "  likely near In[19]:2\n",
      "WARNING: Compat.UTF8String is deprecated, use String instead.\n",
      "  likely near In[19]:2\n",
      "WARNING: Compat.UTF8String is deprecated, use String instead.\n",
      "  likely near In[19]:2\n",
      "WARNING: Compat.UTF8String is deprecated, use String instead.\n",
      "  likely near In[19]:2\n"
     ]
    }
   ],
   "source": [
    "p = plot(sim, [:trace, :mean, :density, :autocor], legend=true);\n",
    "draw(p, ncol=4, filename=\"summaryplot\", fmt=:svg)\n",
    "draw(p, ncol=4, filename=\"summaryplot\", fmt=:pdf)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### @__FILE__ only returns a useful value if the julia script is loaded from a file."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"\""
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ProjDir=@__FILE__"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"/Users/rob/Downloads\""
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pwd()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"/Users/rob/Downloads\""
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ProjDir=pwd()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"/Users/rob/.julia/v0.6/Stan\""
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Pkg.dir(\"Stan\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "v\"0.6.0\""
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "VERSION"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "true"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Sys.isapple()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Julia 0.6.0",
   "language": "julia",
   "name": "julia-0.6"
  },
  "language_info": {
   "file_extension": ".jl",
   "mimetype": "application/julia",
   "name": "julia",
   "version": "0.6.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
